From 6c7f4b78b5652a04db8cb138c785c7efa6bc3a8c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 10 Nov 2015 00:50:42 -0500 Subject: [PATCH] flowbox: Use a CSS node for rubberband drawing Use a CSS node with name rubberband to draw the rubberband selection. --- gtk/gtkflowbox.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index 6b553dfbfc..5c5cb86f4d 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -56,6 +56,7 @@ * * GtkFlowBox uses a single CSS node with name flowbox. GtkFlowBoxChild * uses a single CSS node with name flowboxchild. + * For rubberband selection, a subnode with name rubberband is used. */ #include @@ -67,6 +68,7 @@ #include "gtkintl.h" #include "gtkcssnodeprivate.h" #include "gtkwidgetprivate.h" +#include "gtkstylecontextprivate.h" #include "a11y/gtkflowboxaccessibleprivate.h" #include "a11y/gtkflowboxchildaccessible.h" @@ -813,9 +815,10 @@ struct _GtkFlowBoxPrivate { GtkGesture *multipress_gesture; GtkGesture *drag_gesture; - gboolean rubberband_select; GtkFlowBoxChild *rubberband_first; GtkFlowBoxChild *rubberband_last; + GtkCssNode *rubberband_node; + gboolean rubberband_select; gboolean rubberband_modify; gboolean rubberband_extend; @@ -2564,8 +2567,7 @@ gtk_flow_box_draw (GtkWidget *widget, cairo_save (cr); context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND); + gtk_style_context_save_to_node (context, priv->rubberband_node); iter1 = CHILD_PRIV (priv->rubberband_first)->iter; iter2 = CHILD_PRIV (priv->rubberband_last)->iter; @@ -2637,7 +2639,7 @@ gtk_flow_box_draw (GtkWidget *widget, cairo_append_path (cr, path); cairo_path_destroy (path); - state = gtk_widget_get_state_flags (widget); + state = gtk_style_context_get_state (context); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_style_context_get_border_color (context, state, &border_color); G_GNUC_END_IGNORE_DEPRECATIONS @@ -2863,6 +2865,7 @@ gtk_flow_box_drag_gesture_update (GtkGestureDrag *gesture, GtkFlowBoxPrivate *priv = BOX_PRIV (box); gdouble start_x, start_y; GtkFlowBoxChild *child; + GtkCssNode *widget_node; gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y); @@ -2871,6 +2874,13 @@ gtk_flow_box_drag_gesture_update (GtkGestureDrag *gesture, { priv->rubberband_select = TRUE; priv->rubberband_first = gtk_flow_box_find_child_at_pos (box, start_x, start_y); + + widget_node = gtk_widget_get_css_node (GTK_WIDGET (box)); + priv->rubberband_node = gtk_css_node_new (); + gtk_css_node_set_name (priv->rubberband_node, I_("rubberband")); + gtk_css_node_set_parent (priv->rubberband_node, widget_node); + gtk_css_node_set_state (priv->rubberband_node, gtk_css_node_get_state (widget_node)); + g_object_unref (priv->rubberband_node); /* Grab focus here, so Escape-to-stop-rubberband works */ gtk_flow_box_update_cursor (box, priv->rubberband_first); @@ -3028,6 +3038,9 @@ gtk_flow_box_stop_rubberband (GtkFlowBox *box) priv->rubberband_first = NULL; priv->rubberband_last = NULL; + gtk_css_node_set_parent (priv->rubberband_node, NULL); + priv->rubberband_node = NULL; + remove_autoscroll (box); gtk_widget_queue_draw (GTK_WIDGET (box)); -- 2.30.2